package com.echo.code.spring.tx;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Description
 *
 * @author baiyp
 * @version 1.0.0
 * @date 2019/04/21
 */
@Component
@Transactional
public class UserService {

  @Autowired
  private UserDao userDao;

  @Transactional
  public void addUser(List<User> users) {
    userDao.addUser(users.get(0));
    doSomething();
    userDao.addUser(users.get(1));
  }

  public void doSomething() {
    throw new RuntimeException();
  }
}
